package eclipse.weibo.modle;

import java.util.Map;

import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableItem;

import weibo4j.Status;
import eclipse.weibo.util.Pair;
import eclipse.weibo.util.WeiboUtil;

public class ReadWeiboCountThread extends Thread {
    private Table table;
    private String ids;
    private Display display;
    private Map<String, Pair<Integer, Integer>> map = null;

    public ReadWeiboCountThread(Table table, String ids, Display display) {
        this.table = table;
        this.ids = ids;
        this.display = display;
    }

    public void run() {
        this.map = WeiboUtil.getWeiboNum(this.ids.toString());
        this.display.asyncExec(new TThread());
    }

    class TThread extends Thread {
        public void run() {
            TableItem[] tis = table.getItems();
            for (int i = 0; i < tis.length; ++i) {
                Status s = (Status) tis[i].getData();
                String key = String.valueOf(s.getId());
                Pair<Integer, Integer> pair = map.get(key);
                if(pair!=null){
                    s.setComments(pair.getA().intValue());
                    s.setRt(pair.getB().intValue());

                    tis[i].setText(5, pair.getA().toString());
                    tis[i].setText(6, pair.getB().toString());
                }
            }
        }
    }
}
